/**
 * @created by zhangpeng18 on 2019-8-5 10:40:22
 * @updated by
 * @description Java类驱动管理
 */
define(['./custom/widgets/js/yufpSelectParam.js'],
	function (require, exports) {
		/**
		 * 页面加载完成时触发
		 * @param hashCode 路由ID
		 * @param data 传递数据对象
		 * @param cite 页面站点信息
		 */
		exports.ready = function (hashCode, data, cite) {
			yufp.lookup.reg('USE_TASK_JOB_TYPE,YESNO');
			yufp.custom.vue({
				el: cite.el,
				data: function () {
					var _this = this;
					/*定义校验规则，只能填字母数字 下划线*/
					var valiCodes = function (rule, value, callback) {
						var reg = /^[0-9a-zA-Z_]{1,}$/;
						if (value && reg.test(value)) {
							if (value.length > 64) {
								callback(new Error('长度不能大于64位'));
							} else {
								callback();
							}
						} else if (value && !reg.test(value)) {
							callback(new Error('能填字母、数字和下划线'));
						} else {
							callback();
						}
					};
					/**检验数字为0-255*/
					var numMax = function (rule, value, callback) {
						if (value) {
							if (Number(value) >= 0 && Number(value) <= 255) {
								callback();
							} else {
								callback(new Error('返回值必须为0-255之间'));
							}
						} else {
							callback();
						}
					};
					return {
						rules: {
							actionCode: [
								{ validator: valiCodes, trigger: 'blur' }
							]
						},
						tbHeight:'0',
						searchFormdata: {},
						appNameDisabled: false,
						addFnButton: !yufp.session.checkCtrl('addFn'),
						updateFnButton: !yufp.session.checkCtrl('updateFn'),
						deleteFnButton: !yufp.session.checkCtrl('deleteFn'),
						addClassFnButton: !yufp.session.checkCtrl('addClassFn'),
						updateClassFnButton: !yufp.session.checkCtrl('updateClassFn'),
						deleteClassFnButton: !yufp.session.checkCtrl('deleteClassFn'),
						treeDataUrl: "api/use/plats/worktemplate/queryTreeList",
						dataUrl: 'api/use/plats/worktemplate/queryList',
						saveBtnShow: true,
						cancelBtnShow: true,
						addBtnShow: false,
						activeTabName: "basicInfo",
						formdata: {
							multiFlag: 'N',  //默认为否
							intrFlag: 'Y' //默认为是
						},
						formExecData: {},
						formdataRemark: {},
						async: false,
						height: yufp.frame.size().height - 147,
						folderHeight: 300,
						dialogVisible: false,
						formDisabled: false,
						classCodeDisabled: false,
						viewTitleArrry: ['作业模版添加', '作业模版修改', '作业模版查看'],
						viewTitle: '',
						disabledOpr: false,
						paramcfgDatas: [],
						appCodeShow: true,
						appShowName: "",
						nodeData: '', // 在新增表格数据时需要先获取当前树节点，再把一条新的记录加到这个节点下的表格里,
						nodeLeaf: false,
						isDisabledAppName: false,
						isReadOnly: false,
						isAppNode: false,
						isNodeLeaf: false,
						nodeLeafData: {},
						dataSources: [],
						currentClickNode: {},
						defaultFolderKey: [],
						isClassaddFlag: false,
						classCodeReadOnly: false,
						chooseFolderDialogVisible: false,
						isFileEvent: false,
						currAppNode: {},
						agentIds: [],
						filDatas: [],
						viewClassTitle: "",
						folderRoot: "",
						viewClassTitleArrry: ['作业模版目录添加', '作业模版目录修改'],
						isView: false,
						paramObj: {},
						classDialogVisible: false,
						paramValueValidate: [{ required: true, message: '必填项' },
						{ message: '请输入数字', validator: yufp.validator.number },
						{ validator: numMax, trigger: 'blur' }
						],
						firstStepFormButtons: [
							{
								label: '取消',
								hidden: false,
								click: function () {
									_this.cancelFn();

								}
							},
							{
								label: '下一步',
								type: 'primary',
								hidden: false,
								click: function () {
									_this.nextStepFn();
								}
							},
							{
								label: '保存',
								type: 'primary',
								hidden: true,
								click: function () {
									_this.saveFn();
								}
							}

						],
						classFields: [{
							columnCount: 2,
							fields: [
								{
									field: 'appCode',
									label: '所属应用系统编号:',
									hidden: true
								},
								{
									field: 'appName',
									label: '所属应用系统:',
									disabled: true
								},
								{
									field: 'parentFolder',
									label: '上级目录名称:',
									hidden: true
								},
								{
									field: 'parentFolderName',
									label: '上级目录名称:',
									disabled: true
								},
								{
									field: 'folderCode',
									label: '目录编码',
									maxlength: 64,
									rules: [
										{ validator: valiCodes, trigger: 'blur' }
									]
								},
								{
									field: 'folderName',
									label: '目录名称:',
									maxlength: 120,
									rules: [{ required: true, message: '必填项', trigger: 'blur' },
									{ max: 128, message: '输入值过长', trigger: 'blur' }]
								}

							]

						}, {
							columnCount: 1,
							fields: [

								{
									field: 'remark',
									label: '备注:',
									maxlength: 240,
									type: "textarea",
									rows: 3,
									rules: [{ max: 256, message: '输入值过长', trigger: 'blur' }]
								}
							]
						}],

						classButtons: [
							{
								label: '取消', hidden: false, click: function (model) {
									_this.cancelClassFn();
								}
							},
							{
								label: '保存', type: 'primary', hidden: false, op: 'submit', click: function (model, valid) {
									_this.saveClassCodeFn();
								}
							}
						],

						execInfoFormFields: [
							{
								columnCount: 2,
								fields: [
									{
										field: 'actionLoc',
										label: '位置修饰符:',
										maxlength: 64,
										hidden: false,
										rules: [{ required: true, message: '必填项', trigger: 'blur' },
										{ max: 256, message: '输入值过长', trigger: 'blur' }]
									},
									{
										field: 'actionLocSelect',
										label: '位置修饰符:',
										type: "select",
										hidden: false,
										options: [],
										rules: [{ required: true, message: '必填项', trigger: 'blur' }]
									}
								]

							},
							{
								columnCount: 1,
								fields: [
									{
										field: 'actionExec',
										label: '作业内容:',
										type: "textarea",
										maxlength: 1024,
										rows: 3,
										rules: [{ required: true, message: '必填项', trigger: 'blur' }]

									}
								]

							}
						],

						tableColumns: [
							{ label: '编号', type: "index" },
							{ label: '系统名称', prop: 'appName', hidden: false },
							{
								label: '作业模版代码',
								prop: 'actionCode',
								template: function () {
									return '<template scope="scope">\
                               <a style="text-decoration:underline;color:#636CE4 " href="javascipt:void(0);"  @click="_$event(\'custom-detail-click\', scope.row)">{{ scope.row.actionCode }}</a>\
                           </template>';
								}
							},
							{ label: '作业模版名称', prop: 'actionName' },
							{ label: '目录路径', prop: 'folderPath' },
							{ label: '作业类型', prop: 'typeCode', dataCode: 'USE_TASK_JOB_TYPE' },
							{ label: '备注', prop: 'remark' }
						],


						queryButtons: [
							{
								label: '搜索', op: 'submit', type: 'primary', click: function (model, valid) {
									var paramObject = {};


									let appCode = "";
									let folderCode = "";

									if (_this.currentClickNode != null && _this.currentClickNode.nodeType != 'R') {
										appCode = _this.currentClickNode.appCode;
										if (_this.currentClickNode.nodeType === 'C') {
											folderCode = _this.currentClickNode.currentNodeId
										}

									}


									model.appCode = appCode;
									model.folderCode = folderCode;


									var param = { condition: JSON.stringify(model) };
									_this.$refs.refTable.remoteData(param);
								}
							},
							{ label: '重置', op: 'reset' }
						],


						//isReadOnly: false,
						nodeTemp: {},
					};
				},
				mounted:function(){
					var _this = this;
					//测试
					_this.$nextTick(function(){
							var tableBox = _this.$refs.tableBox;
							let a = tableBox.getBoundingClientRect().top + 28;
							var theight = `calc(100vh - ${a}px - 64px)`;
							_this.tbHeight = theight;		
					});
				},
				methods: {

					getSelectedData: function (data) {
						var _this = this;
						_this.$refs.paramsTab.data[0].paramName = data[0].paramName;
					},
					createTreeFn: function () {
						var _this = this;
						if (_this.currentClickNode == null
							|| _this.currentClickNode.nodeType == null
							|| _this.currentClickNode.nodeType === 'R') {
							_this.$message("请选择一个应用系统或目录");
							return;
						}

						// _this.$set( _this.classFields[0].fields[4], 'readonly',  false);
						_this.classDialogVisible = true;
						_this.viewClassTitle = _this.viewClassTitleArrry[0];
						_this.isClassaddFlag = true;
						_this.$nextTick(function () {
							_this.$refs.refClassForm.switch(_this.classFields[0].fields[4].field, 'disabled', false);
							_this.$refs.refClassForm.resetFields();
							_this.$refs.refClassForm.formModel.appCode = _this.currentClickNode.appCode;
							_this.$refs.refClassForm.formModel.appName = _this.currentClickNode.appName;

							if (_this.currentClickNode.nodeType === 'A') {
								_this.$refs.refClassForm.formModel.parentFolder = " ";
								_this.$refs.refClassForm.formModel.parentFolderName = "应用根目录";
							} else {
								_this.$refs.refClassForm.formModel.parentFolder = _this.currentClickNode.currentNodeId;
								_this.$refs.refClassForm.formModel.parentFolderName = _this.currentClickNode.currentNodeName;
							}


						});

					},
					cancelClassFn: function () {
						var _this = this;
						this.classDialogVisible = false;
					},

					selectFolder: function () {
						var _this = this;
						if (_this.addFlag) {
							_this.folderRoot = _this.currentClickNode.appCode;
						} else {
							_this.folderRoot = _this.$refs.refTable.selections[0].appCode;
						}

						_this.defaultFolderKey.splice(0);
						if (_this.formdata.folderCode != null) {
							_this.defaultFolderKey.push(_this.formdata.folderCode);

						}

						_this.chooseFolderDialogVisible = true;
						_this.$nextTick(function () {
							_this.$refs.refFolderTree.remoteData({});
						});

					},

					saveClassCodeFn: function () {

						var _this = this;
						var validate = false;
						_this.$refs.refClassForm.validate(function (valid) {
							validate = valid;
						});
						if (!validate) {
							return;
						}

						let urlparam = "";

						if (_this.isClassaddFlag) {
							urlparam = 'api/use/plats/worktemplate/saveCatalog';
						} else {
							urlparam = 'api/use/plats/worktemplate/updateCatalog';
						}
						yufp.service.request({
							method: 'POST',
							url: urlparam,
							data: _this.$refs.refClassForm.formModel,
							callback: function (code, message, response) {

								if (response.code == 0) {
									_this.$message('操作成功');
									_this.classDialogVisible = false;
									_this.$refs.refTree.remoteData({});
								} else {
									_this.$message({ message: response.message, type: "warning" });
								}
							}
						});

					},


					updateTreeFn: function () {
						var _this = this;

						if (_this.currentClickNode.nodeType != 'C') {
							_this.$message({ message: "请选择一个事件目录", type: "warning" });
							return;
						}

						// _this.$set( _this.classFields[0].fields[4], 'readonly',  true);

						_this.classDialogVisible = true;
						_this.viewClassTitle = _this.viewClassTitleArrry[1];
						_this.isClassaddFlag = false;
						_this.classCodeReadOnly = true;
						_this.$nextTick(function () {
							_this.$refs.refClassForm.switch(_this.classFields[0].fields[4].field, 'disabled', true);
							_this.$refs.refClassForm.resetFields();
							_this.$refs.refClassForm.formModel.appCode = _this.currentClickNode.appCode;
							_this.$refs.refClassForm.formModel.appName = _this.currentClickNode.appName;
							_this.$refs.refClassForm.formModel.parentFolder = _this.currentClickNode.parentId;
							_this.$refs.refClassForm.formModel.parentFolderName = _this.currentClickNode.parentName;
							_this.$refs.refClassForm.formModel.folderCode = _this.currentClickNode.currentNodeId;
							_this.$refs.refClassForm.formModel.folderName = _this.currentClickNode.currentNodeName;
							_this.$refs.refClassForm.formModel.remark = _this.currentClickNode.remark;
						});

					},
					deleteTreeFn: function () {
						var _this = this;

						if (_this.currentClickNode.nodeType != 'C') {
							_this.$message({ message: "请选择一个文件目录", type: "warning" });
							return;
						}
						_this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning',
							duration: 6000,
							center: true,
							callback: function (action) {
								if (action === 'confirm') {
									let paramObj = {};
									paramObj.appCode = _this.currentClickNode.appCode;
									paramObj.folderCode = _this.currentClickNode.currentNodeId;

									yufp.service.request({
										method: 'DELETE',
										url: "api/use/plats/worktemplate/deleteCatalog",
										data: paramObj,
										callback: function (code, message, response) {
											if (response.code != 0) {
												_this.$message({ message: response.message, type: "warning" });
											} else {
												_this.$message('操作成功');
												_this.$refs.refTree.remoteData({});
												var paramObject = {};
												paramObject.appCode = _this.currentClickNode.appCode;

												_this.$refs.refTable.remoteData({ condition: paramObject });
											}

										}
									});
								}
							}
						});
					},


					/**
					 * 取消
					 */
					cancelFn: function () {
						var _this = this;
						_this.dialogVisible = false;
					},
					/**
					 * 保存
					 */
					saveFn: function () {


						var _this = this;
						var validate = false;
						_this.$refs.refForm.validate(function (valid) {
							validate = valid;
						});
						if (!validate) {
							return;
						}

						var paramObj = _this.formdata;

						if (paramObj.typeCode != '-') {
							_this.$refs.refExecForm.validate(function (valid) {
								validate = valid;
							});

							if (!validate) {
								return;
							}

							//检验参数信息
							if (_this.paramcfgDatas.length > 0) {
								var paramNoList = [];
								for (let i = 0; i < _this.paramcfgDatas.length; i++) {
									if (_this.paramcfgDatas[i].paramNo == '' || _this.paramcfgDatas[i].paramNo == null
										|| !_this.checkNum(_this.paramcfgDatas[i].paramNo)) {
										_this.$message({ message: "[参数信息->参数编号]必须为数字类型", type: "warning" });
										return
									} else {
										for (var j = 0; j < paramNoList.length; j++) {
											if (paramNoList[j] === _this.paramcfgDatas[i].paramNo) {
												_this.$message({ message: "参数编号重复【" + paramNoList[j] + "】，请检查", type: "warning" });
												return
											}
										}

										paramNoList.push(_this.paramcfgDatas[i].paramNo);
									}
									if (_this.paramcfgDatas[i].paramName == '' || _this.paramcfgDatas[i].paramName == null) {
										_this.$message({ message: "参数名字不能为空", type: "warning" });
										return
									}

									if (_this.paramcfgDatas[i].paramValue == '' || _this.paramcfgDatas[i].paramValue == null) {
										_this.$message({ message: "参数值不能为空", type: "warning" });
										return
									}
								}

								paramObj.useCatalogParamList = _this.paramcfgDatas;
							}



							if (_this.$refs.refExecForm.formModel.actionLocSelect != null
								&& _this.$refs.refExecForm.formModel.actionLocSelect != '') {
								paramObj.actionLoc = _this.$refs.refExecForm.formModel.actionLocSelect;
							} else {

								if (_this.$refs.refExecForm.formModel.actionLoc != null && _this.$refs.refExecForm.formModel.actionLoc != "") {
									paramObj.actionLoc = _this.$refs.refExecForm.formModel.actionLoc;
								} else {
									paramObj.actionLoc = " ";
								}

							}
							paramObj.actionExec = _this.$refs.refExecForm.formModel.actionExec;




						} else {
							paramObj.actionLoc = " ";
							paramObj.actionExec = " ";
						}



						//paramObj.remark = _this.$refs.refFormMark.formdata.remark;

						let urlparam = "";
						if (_this.addFlag) {

							urlparam = 'api/use/plats/worktemplate/saveTemplate';

						} else {
							urlparam = 'api/use/plats/worktemplate/updateTemplate';
						}
						yufp.service.request({
							method: 'POST',
							url: urlparam,
							data: paramObj,
							callback: function (code, message, response) {
								if (response.code == 0) {

									let appCode = "";
									let folderCode = "";

									if (_this.currentClickNode.nodeType != 'R') {
										appCode = _this.currentClickNode.appCode;
										if (_this.currentClickNode.nodeType === 'C') {
											folderCode = _this.currentClickNode.currentNodeId;
										}

									}

									var paramObj = {};
									paramObj.appCode = appCode;
									paramObj.folderCode = folderCode;
									var param = { condition: JSON.stringify(paramObj) };
									_this.$refs.refTable.remoteData(param);
									_this.$message('操作成功');
									_this.dialogVisible = false;
								} else {
									_this.$message({ message: response.message, type: "warning" });
								}
							}
						});





					},




					folderNodeClickFn: function (nodeData) {



						var checkObjects = this.$refs.refFolderTree.getCheckedNodes();
						for (var i = 0; i < checkObjects.length; i++) {
							if (nodeData.currentNodeId === checkObjects[i].currentNodeId) {
								continue;
							} else {
								this.$refs.refFolderTree.setChecked(checkObjects[i], false);
							}
						}

					},

					selectFolderSaveFn: function () {
						var _this = this;
						var checkObjects = this.$refs.refFolderTree.getCheckedNodes();
						if (checkObjects.length != 1) {
							_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
							return;
						} else {
							_this.formdata.folderCode = checkObjects[0].currentNodeId;
							_this.formdata.folderName = checkObjects[0].currentNodeName;
							_this.chooseFolderDialogVisible = false;
						}
					},

					selectFolderCancelFn: function () {
						var _this = this;
						var checkObjects = this.$refs.refFolderTree.getCheckedNodes();
						for (var i = 0; i < checkObjects.length; i++) {
							this.$refs.refFolderTree.setChecked(checkObjects[i], false);
						}

						_this.chooseFolderDialogVisible = false;
					},

					/**
					 * 点击树的结点，加载对应的数据
					 */
					nodeClickFn: function (nodeData, node, self) {

						console.log(nodeData);
						var _this = this;
						_this.currentClickNode = nodeData;
						let appCode = "";
						let folderCode = "";

						if (nodeData.nodeType != 'R') {
							_this.isNodeLeaf = true;
							_this.tableColumns[1].hidden = true;
							_this.appNameDisabled = true;
							_this.searchFormdata.appName = nodeData.appName;
							appCode = nodeData.appCode;
							_this.paramObj.appCode = nodeData.appCode;
							if (nodeData.nodeType === 'C') {
								folderCode = nodeData.currentNodeId
							}

						} else {
							_this.isNodeLeaf = false;
							_this.appNameDisabled = false;
							_this.searchFormdata.appName = '';
							_this.tableColumns[1].hidden = false;
							_this.paramObj.appCode = "";
						}

						//var paramObj = {};
						_this.searchFormdata.appCode = appCode;
						_this.searchFormdata.folderCode = folderCode;
						var param = { condition: JSON.stringify(_this.searchFormdata) };
						_this.$refs.refTable.remoteData(param);

					},
					/**
					 * 新增
					 */
					addFn: function () {
						var _this = this;
						_this.viewTitle = _this.viewTitleArrry[0];
						_this.addFlag = true;
						_this.isReadOnly = false;
						_this.isFileEvent = false;
						_this.dialogVisible = true;
						_this.activeTabName = "basicInfo";
						_this.isView = false;
						_this.$nextTick(function () {
							_this.$refs.refForm.resetFields();
							_this.$refs.refExecForm.resetFields();
							_this.paramcfgDatas.splice(0);
							_this.formdata.appCode = _this.currentClickNode.appCode;
							_this.queryWftAgtList();
							_this.formdata.appName = _this.currentClickNode.appName;
							if (_this.currentClickNode.currentNodeId === _this.currentClickNode.appCode) {
								_this.formdata.folderCode = _this.currentClickNode.currentNodeId;
								_this.formdata.folderName = "应用根目录";
							} else {
								_this.formdata.folderCode = _this.currentClickNode.currentNodeId;
								_this.formdata.folderName = _this.currentClickNode.currentNodeName;
							}


							/*  _this.formdata.appName = _this.nodeLeafData.parentName;
								_this.formdata.className = _this.nodeLeafData.appName;
								_this.formdata.paramType="C";*/

						});
					},


					viewDataFn: function (data) {
						var _this = this;
						_this.isView = true;
						_this.isReadOnly = true;
						_this.viewTitle = _this.viewTitleArrry[2];
						_this.dialogVisible = true;
						_this.addFlag = false;
						_this.activeTabName = "basicInfo";
						_this.paramObj.appCode = data.appCode;

						_this.$nextTick(function () {

							_this.$refs.refExecForm.resetFields();
							_this.$refs.refForm.resetFields();
							_this.paramcfgDatas.splice(0);
							_this.queryWftAgtList();
							_this.queryParamstList(data);

							yufp.extend(_this.formdata, data);
							yufp.extend(_this.$refs.refExecForm.formModel, data);
							_this.selectTypeCodeFn(data.typeCode, _this.formdata);
						});
					},
					/**
					 * 修改
					 */
					modifyFn: function () {
						var _this = this;
						if (_this.$refs.refTable.selections.length != 1) {
							_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
							return;
						}

						_this.isView = false;

						_this.isReadOnly = true;
						_this.viewTitle = _this.viewTitleArrry[1];
						_this.dialogVisible = true;
						_this.addFlag = false;
						_this.activeTabName = "basicInfo";
						_this.paramObj.appCode = _this.$refs.refTable.selections[0].appCode;
						_this.$nextTick(function () {

							_this.$refs.refExecForm.resetFields();
							_this.$refs.refForm.resetFields();
							_this.paramcfgDatas.splice(0);
							_this.queryWftAgtList();
							_this.queryParamstList(_this.$refs.refTable.selections[0]);

							yufp.extend(_this.formdata, _this.$refs.refTable.selections[0]);
							yufp.extend(_this.$refs.refExecForm.formModel, _this.$refs.refTable.selections[0]);
							_this.selectTypeCodeFn(_this.$refs.refTable.selections[0].typeCode, _this.formdata);
						});
					},
					/**
					 * 删除
					 */
					deleteFn: function () {
						var _this = this;
						var selections = _this.$refs.refTable.selections;
						if (selections.length != 1) {
							_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
							return;
						}

						_this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning',
							duration: 6000,
							center: true,
							callback: function (action) {
								if (action === 'confirm') {
									yufp.service.request({
										method: 'DELETE',
										url: "api/use/plats/worktemplate/deleteTemplate",
										data: selections[0],
										callback: function (code, message, response) {
											if (response.code != 0) {
												isOk = false;
												_this.$message({ message: response.message, type: "warning" });
											} else {
												let appCode = "";
												let folderCode = "";

												if (_this.currentClickNode.nodeType != 'R') {
													appCode = _this.currentClickNode.appCode;
													if (_this.currentClickNode.nodeType === 'C') {
														folderCode = _this.currentClickNode.currentNodeId;
													}

												}

												var paramObj = {};
												paramObj.appCode = appCode;
												paramObj.folderCode = folderCode;
												var param = { condition: JSON.stringify(paramObj) };
												_this.$refs.refTable.remoteData(param);
												_this.$message('操作成功');
												_this.dialogVisible = false;

											}

										}
									});
								}
							}
						});
					},

					queryWftAgtList: function () {
						var _this = this;
						var paramObj = {};
						if (_this.addFlag) {
							paramObj.appCode = _this.currentClickNode.appCode;
						} else {
							paramObj.appCode = _this.$refs.refTable.selections[0].appCode;
						}


						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/apps/queryWftAgtList",
							data: paramObj,
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									isOk = false;
									_this.$message(response.message);
								} else {
									_this.agentIds.splice(0);
									_this.agentIds.push({ key: " ", value: "虚拟代理" });
									for (let i = 0; i < response.data.length; i++) {
										_this.agentIds.push({ key: response.data[i].agentCode, value: response.data[i].agentName });
									}
								}

							}
						});
					},
					addParamData: function () {
						var obj = { paramNo: "", paramName: "", paramValue: "", remark: "" };
						this.paramcfgDatas.push(obj);

					},
					deleteParamData: function () {

						var _this = this;

						let selectDatas = _this.$refs.paramsTab.selections;
						for (let jdx = _this.paramcfgDatas.length - 1; jdx >= 0; jdx--) {
							for (let idx = 0; selectDatas.length > idx; idx++) {
								if (_this.paramcfgDatas[jdx] == selectDatas[idx]) {
									_this.paramcfgDatas.splice(jdx, 1);
									break;
								}
							}

						}

					},
					nextStepFn: function () {

						var _this = this;
						var validate = false;
						_this.$refs.refForm.validate(function (valid) {
							validate = valid;
						});
						if (!validate) {
							return;
						} else {
							this.activeTabName = "execInfo";
						}


					},

					selectTypeCodeFn: function (val, Obj) {

						if (val === '-' || val === '+') {
							this.formdata.agentCode = ' ';
							this.formdata.multiFlag = 'N';
							this.formdata.intrFlag = 'N';
							this.disabledOpr = true;
						} else {
							this.disabledOpr = false;
						}


						if (val === '-') {
							this.firstStepFormButtons[1].hidden = true;
							this.firstStepFormButtons[2].hidden = false;
							this.execInfoFormFields[0].fields[0].hidden = true;
							this.execInfoFormFields[0].fields[1].hidden = true;
						} else {
							this.firstStepFormButtons[1].hidden = false;
							this.firstStepFormButtons[2].hidden = true;
							if (val === '+' || val === 'D' || val === 'I' || val === 'J' || val === 'M' || val === 'R' || val === 'S' || val === 'T' || val === 'Q') {
								this.execInfoFormFields[0].fields[0].hidden = true;
								this.execInfoFormFields[0].fields[1].hidden = false;
								this.execInfoFormFields[0].fields[0].rules.splice(0);
								if (this.execInfoFormFields[0].fields[1].rules.length == 0) {
									this.execInfoFormFields[0].fields[1].rules.push({ required: true, message: '必填项', trigger: 'blur' });
								}
								let url = "";
								if (val === '+') { //流程
									url = "api/use/plats/apps/getTreeWftList";
								} else if (val === 'D') { //DS作业
									url = "api/use/plats/dscfg/queryList";
								} else if (val === 'I') { //Infa会话
									url = "api/use/plats/pccfg/queryList"
								} else if (val === 'J') { // javaclass
									url = "api/use/plats/jccfg/queryList"
								} else if (val === 'M' || val === 'R' || val === 'S' || val === 'Q') { //数据源
									url = "api/use/plats/rdbcfg/queryList"
								} else if (val === 'T') { //Tuxedo服务
									url = "api/use/plats/txdcfg/queryList";
								}
								this.loadRelTypeCodeDatas(this.execInfoFormFields[0].fields[1].options,
									url, val, { appCode: this.formdata.appCode });
								if (Obj != null) {
									this.$refs.refExecForm.formModel.actionLocSelect = Obj.actionLoc;
								}

							} else if (val === 'C') {
								this.execInfoFormFields[0].fields[0].hidden = true;
								this.execInfoFormFields[0].fields[1].hidden = true;
								this.execInfoFormFields[0].fields[0].rules.splice(0);
								this.execInfoFormFields[0].fields[1].rules.splice(0);
							} else {
								this.execInfoFormFields[0].fields[0].hidden = false;
								this.execInfoFormFields[0].fields[1].hidden = true;
								this.execInfoFormFields[0].fields[1].rules.splice(0);
								this.execInfoFormFields[0].fields[0].rules.splice(0);
								this.execInfoFormFields[0].fields[0].rules.push({ required: true, message: '必填项', trigger: 'blur' });
								this.execInfoFormFields[0].fields[0].rules.push({ max: 64, message: '输入值最长为64字节', trigger: 'blur' });
							}


						}

					},
					lastStep: function () {
						this.activeTabName = "basicInfo";
					},

					loadRelTypeCodeDatas: function (options, url, type, params) {
						yufp.service.request({
							method: 'GET',
							url: url,
							data: params,
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									isOk = false;
									_this.$message(response.message);
								} else {
									options.splice(0);
									for (let i = 0; i < response.data.length; i++) {
										if (type === '+') {
											if (response.data[i].appCode != '0000') {
												options.push({ key: response.data[i].appCode, value: response.data[i].appName });
											}

										} else {
											options.push({ key: response.data[i].classCode, value: response.data[i].className });
										}
									}
								}

							}
						});

					},

					checkNum: function (value) {
						var reg = /^\d+$/;
						if (value && reg.test(value)) {
							return true;
						} else if (value && !reg.test(value)) {
							return false;
						} else {
							return true;
						}
					},

					queryParamstList: function (paramObj) {
						var _this = this;
						var newParam = {};
						newParam.appCode = paramObj.appCode;
						newParam.actionCode = paramObj.actionCode;

						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/worktemplate/queryParamsList",
							data: newParam,
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									isOk = false;
									_this.$message(response.message);
								} else {
									for (let i = 0; i < response.data.length; i++) {
										_this.paramcfgDatas.push(response.data[i]);
									}
								}

							}
						});
					},

				},

			});
		};
	});